package com.wiken.servicecommon.common.exception;

import com.wiken.servicecommon.common.Code;
import com.wiken.servicecommon.common.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R globalException(Exception e){
        System.out.println(e.getMessage());
        return R.error().code(Code.ERROR).message("很抱歉，出现了些差错");
    }

    @ExceptionHandler(value = DefaultException.class)
    @ResponseBody
    public R defaultException(DefaultException e){

        return R.error().code(e.getCode()).message(e.getMessage());
    }
}
